package view;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.BevelBorder;

import view.b4.advancedgui.menu.AccordionMenu;
import controller.MenuController;
import entidad.Persona;

public class FrmMenu extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel cont2;
	private JPanel pnlMenu;
	public JTextField txtMessage;
	public JMenuBar menuBar;
	public AccordionMenu menu;
	//public int cargoPersona;
	private MenuController menuController = new MenuController(this);
	public JDesktopPane desktopPane;
	public  Persona persona;
	public JMenuItem mntmCerrarSesion;
	public JMenuItem mntmSalir;
	public JMenu mnArchivo;
	
	

	public FrmMenu(Persona persona) {
		this.persona = persona;
		//P

		setAutoRequestFocus(false);
		setSize(1080, 699);
		try {
			setIconImage(Toolkit
					.getDefaultToolkit()
					.getImage(
							this.getClass()
									.getResource(
											"b4/advancedgui/menu/resources/green_arrow_right.png")));
		} catch (Exception ex) {
			Logger.getLogger(FrmMenu.class.getName()).log(Level.SEVERE, null,
					ex);
		}
		cont2 = new JPanel();
		pnlMenu = new JPanel();
		txtMessage = new JTextField();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setBackground(new java.awt.Color(255, 204, 204));

		pnlMenu.setOpaque(false);
		pnlMenu.setLayout(new java.awt.GridLayout(1, 3, 30, 0));

		cont2.setBackground(new java.awt.Color(153, 153, 153));
		cont2.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0,
				0, 0), 1, true));
		cont2.setLayout(new javax.swing.BoxLayout(cont2,
				javax.swing.BoxLayout.LINE_AXIS));
		pnlMenu.add(cont2);

		desktopPane = new JDesktopPane();
		txtMessage.setEditable(false);

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		layout.setHorizontalGroup(layout
				.createParallelGroup(Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addContainerGap()
								.addGroup(
										layout.createParallelGroup(
												Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addComponent(
																		pnlMenu,
																		GroupLayout.PREFERRED_SIZE,
																		204,
																		GroupLayout.PREFERRED_SIZE)
																.addPreferredGap(
																		ComponentPlacement.RELATED)
																.addComponent(
																		desktopPane,
																		GroupLayout.DEFAULT_SIZE,
																		850,
																		Short.MAX_VALUE))
												.addComponent(
														txtMessage,
														GroupLayout.DEFAULT_SIZE,
														1050, Short.MAX_VALUE))
								.addGap(4)));
		layout.setVerticalGroup(layout
				.createParallelGroup(Alignment.TRAILING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(3)
																.addComponent(
																		desktopPane,
																		GroupLayout.DEFAULT_SIZE,
																		600,
																		Short.MAX_VALUE))
												.addGroup(
														layout.createSequentialGroup()
																.addGap(4)
																.addComponent(
																		pnlMenu,
																		GroupLayout.DEFAULT_SIZE,
																		599,
																		Short.MAX_VALUE)))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addComponent(txtMessage,
										GroupLayout.PREFERRED_SIZE,
										GroupLayout.DEFAULT_SIZE,
										GroupLayout.PREFERRED_SIZE)
								.addContainerGap()));
		GroupLayout gl_desktopPane = new GroupLayout(desktopPane);
		gl_desktopPane.setHorizontalGroup(gl_desktopPane.createParallelGroup(
				Alignment.LEADING).addGap(0, 629, Short.MAX_VALUE));
		gl_desktopPane.setVerticalGroup(gl_desktopPane.createParallelGroup(
				Alignment.LEADING).addGap(0, 409, Short.MAX_VALUE));
		desktopPane.setLayout(gl_desktopPane);
		getContentPane().setLayout(layout);

		// menu 2. Creates a menu with 38px as Item height,dark gray background
		// and white foreground, Default Aligmnet of items, two new icon for
		// Leafs.
		menu = new AccordionMenu();
		menuController.creaMenuPorCargo(persona.getIdCargo());
		menu.setBackground(new Color(111, 111, 111));
		menu.setForeground(Color.white);
		menu.setFont(new Font("monospaced", Font.PLAIN, 17));
		menu.setMenusSize(38);
		menu.setMenuBorders(new BevelBorder(BevelBorder.RAISED));
		ImageIcon icon1 = new ImageIcon(this.getClass().getResource(
				"b4/advancedgui/menu/resources/circle_grey.png"));
		ImageIcon icon2 = new ImageIcon(this.getClass().getResource(
				"b4/advancedgui/menu/resources/circle_red.png"));
		menu.setAllLeafIcons(icon1, icon2);
		menuController.setMouseAdapter(menu);

		cont2.add(menu);
		//las vistas por cargo
		menuController.accionPorCargo(persona.getIdCargo());

		menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		mnArchivo = new JMenu("Archivo");
		menuBar.add(mnArchivo);

		mntmCerrarSesion = new JMenuItem("Cerrar Sesion");
		mntmCerrarSesion.addActionListener(menuController);
		mnArchivo.add(mntmCerrarSesion);

		mntmSalir = new JMenuItem("Salir");
		mntmSalir.addActionListener(menuController);
		mnArchivo.add(mntmSalir);

		JMenu mnAyuda = new JMenu("Ayuda");
		menuBar.add(mnAyuda);
		

	}

}
